// 1. 导入所需模块
import Vue from 'vue'
import VueRouter from 'vue-router'
import MyHome from '../components/MyHome.vue'
import MyMovie from '../components/MyMovie.vue'
import MyMusic from '../components/MyMusic.vue'
import MyAbout from '../components/MyAbout.vue'
import AboutMe from '../components/AboutMe.vue'
import AboutYou from '../components/AboutYou.vue'
import NotFound from '../components/NotFound.vue'
// 2. 调用 Vue.use() 函数，将 VueRouter 安装为 Vue 的插件
Vue.use(VueRouter)

// 3. 创建路由的实例对象
const router = new VueRouter({
  // 配置使用哪种模式，默认是hash模式
  mode: 'history', //配置成历史模式
  /*一会要写路由的配置*/
  routes: [
    { path: '/', redirect: '/home' }, // 重定向，当访问/时，将hash地址转到 /home
    { path: '/home', component: MyHome },
    { path: '/movie/:id/:name', component: MyMovie },
    { path: '/music', component: MyMusic },
    {
      path: '/about',
      component: MyAbout,
      children: [
        { path: 'me', component: AboutMe },
        { path: 'you', component: AboutYou }
      ]
    },
    //针对访问错误，给出404提示
    { path: '*', component: NotFound }
  ]
})

// 4. 导出路由的实例对象
export default router
